package com.ruoyi.web.controller.system;


import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.domain.entity.SysNotification;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.ISysNotificationService;

/**
 * 通知Controller
 */
@RestController
@RequestMapping("/system/notification")
public class SysNotificationController extends BaseController {
    @Autowired
    private ISysNotificationService notificationService;

    /**
     * 查询通知列表
     */
    @PreAuthorize("@ss.hasPermi('system:notification:list')")
    @GetMapping("/list")
    public AjaxResult list(SysNotification notification) {
        List<SysNotification> list = notificationService.selectNotificationList(notification);
        return AjaxResult.success(list);
    }

    /**
     * 导出通知列表
     */
    @PreAuthorize("@ss.hasPermi('system:notification:export')")
    @Log(title = "通知", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysNotification notification) {
        List<SysNotification> list = notificationService.selectNotificationList(notification);
        ExcelUtil<SysNotification> util = new ExcelUtil<SysNotification>(SysNotification.class);
        return util.exportExcel(list, "通知数据");
    }

    /**
     * 获取通知详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:notification:query')")
    @GetMapping(value = "/{notificationId}")
    public AjaxResult getInfo(@PathVariable("notificationId") Long notificationId) {
        return AjaxResult.success(notificationService.selectNotificationById(notificationId));
    }

    /**
     * 新增通知
     */
    @PreAuthorize("@ss.hasPermi('system:notification:add')")
    @Log(title = "通知", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysNotification notification) {
        notification.setCreateBy(getUsername());
        return toAjax(notificationService.insertNotification(notification));
    }

    /**
     * 修改通知
     */
    @PreAuthorize("@ss.hasPermi('system:notification:edit')")
    @Log(title = "通知", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysNotification notification) {
        notification.setUpdateBy(getUsername());
        return toAjax(notificationService.updateNotification(notification));
    }

    /**
     * 删除通知
     */
    @PreAuthorize("@ss.hasPermi('system:notification:remove')")
    @Log(title = "通知", businessType = BusinessType.DELETE)
    @DeleteMapping("/{notificationIds}")
    public AjaxResult remove(@PathVariable Long[] notificationIds) {
        return toAjax(notificationService.deleteNotificationByIds(notificationIds));
    }
}